<template>
  <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      :default-active="onRoutes"
      :collapse="collapse"
      background-color="#324157"
      text-color="#bfcbd9"
      active-text-color="#20a0ff"
      unique-opened
      router
    >
      <template v-for="item in items">
        <template v-if="item.subs && item.index==11 && packAuth=='true'">
          <el-submenu :index="item.index" :key="item.index">
            <template slot="title">
              <i :class="item.icon"></i>
              <span slot="title">{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs">
              <el-submenu
                v-if="subItem.subs"
                :index="subItem.index"
                :key="subItem.index"
              >
                <template slot="title">{{ subItem.title }}</template>
                <el-menu-item
                  v-for="(threeItem, i) in subItem.subs"
                  :key="i"
                  :index="threeItem.index"
                  >{{ threeItem.title }}</el-menu-item
                >
              </el-submenu>
              <el-menu-item
                v-else
                :index="subItem.index"
                :key="subItem.index"
                >{{ subItem.title }}</el-menu-item
              >
            </template>
          </el-submenu>
        </template>
		<template v-else-if="item.subs && item.index!=11">
			<el-submenu :index="item.index" :key="item.index">
			  <template slot="title">
			    <i :class="item.icon"></i>
			    <span slot="title">{{ item.title }}</span>
			  </template>
			  <template v-for="subItem in item.subs">
			    <el-submenu
			      v-if="subItem.subs"
			      :index="subItem.index"
			      :key="subItem.index"
			    >
			      <template slot="title">{{ subItem.title }}</template>
			      <el-menu-item
			        v-for="(threeItem, i) in subItem.subs"
			        :key="i"
			        :index="threeItem.index"
			        >{{ threeItem.title }}</el-menu-item
			      >
			    </el-submenu>
			    <el-menu-item
			      v-else
			      :index="subItem.index"
			      :key="subItem.index"
			      >{{ subItem.title }}</el-menu-item
			    >
			  </template>
			</el-submenu>
		</template>
       <!-- <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <i :class="item.icon"></i>
            <span slot="title">{{ item.title }}</span>
          </el-menu-item>
        </template> -->
      </template>
    </el-menu>
  </div>
</template>

<script>
import bus from "../common/bus";
import { routerObj } from "./routerArr";

export default {
  data() {
    return {
      collapse: false,
      items: [],
	  packAuth:localStorage.getItem('packAuth'),//是否授权商家产品包
    };
  },
  computed: {
    onRoutes() {
      return this.$route.path.replace("/", "");
    },
  },
  mounted() {
    // 通过 Event Bus 进行组件间通信，来折叠侧边栏
    let role = localStorage.getItem("role");
    console.log(role, role.includes("decoration"), "-----");
    if (role.includes("shop")) {
      this.items = [...routerObj.shop];
    } else if (role.includes("designer")) {
      this.items = [...routerObj.designer];
    } else if (role.includes("builder")) {
      this.items = [...routerObj.builder];
    } else if (role.includes("decoration")) {
      this.items = [...routerObj.decoration];
    }
    bus.$on("collapse", (msg) => {
      this.collapse = msg;
      bus.$emit("collapse-content", msg);
    });
  },
};
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 60px;
  bottom: 0;
  overflow-y: scroll;
  /* padding-bottom: 50px; */
}
.sidebar::-webkit-scrollbar {
  width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
  width: 220px;
}
.sidebar > ul {
  height: 100%;
}
.sidebar > ul > li {
  padding-left: 0px;
  color: rgb(255, 255, 255);
  background-color: rgb(45, 58, 75);
}
</style>
